<?php

declare(strict_types=1);

namespace App\Queue\Consumer;

use ApiClient\Order\Interfaces\OrderServiceInterface;
use Hyperf\Amqp\Result;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Di\Annotation\Inject;
use PhpAmqpLib\Message\AMQPMessage;
use Throwable;

#[Consumer(exchange: 'demo', routingKey: 'demo', queue: 'demo', name: "DemoConsumer", nums: 3)]
class DemoConsumer extends ConsumerMessage
{
    #[Inject]
    protected OrderServiceInterface $orderServiceClient;

    public function consumeMessage($data, AMQPMessage $message): Result
    {
        var_dump(6666);
        var_dump($data);
        // 这里可以调用 order-service
        try {
            $this->orderServiceClient->getList();
        } catch (Throwable $throwable) {
            // 重试机制
        }
        return Result::ACK;
    }
}
